package com.ruoyi.ebike.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ebike.domain.EbikeUser;
import com.ruoyi.ebike.service.IEbikeUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@RestController
@RequestMapping("/ebikeUser/ebikeUser")
public class UserController extends BaseController
{
    @Autowired
    private IEbikeUserService ebikeUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(EbikeUser ebikeUser)
    {
        startPage();
        List<EbikeUser> list = ebikeUserService.selectEbikeUserList(ebikeUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EbikeUser ebikeUser)
    {
        List<EbikeUser> list = ebikeUserService.selectEbikeUserList(ebikeUser);
        ExcelUtil<EbikeUser> util = new ExcelUtil<EbikeUser>(EbikeUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ebikeUserService.selectEbikeUserById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EbikeUser ebikeUser)
    {
        return toAjax(ebikeUserService.insertEbikeUser(ebikeUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EbikeUser ebikeUser)
    {
        return toAjax(ebikeUserService.updateEbikeUser(ebikeUser));
    }


    /**
     * 清空用户实名信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping("/ebikeUserRealInfo")
    public AjaxResult editRealInfo(@RequestBody EbikeUser ebikeUser) {
        return toAjax(ebikeUserService.updateEbikeUserRealInfo(ebikeUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:ebikeUser:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ebikeUserService.deleteEbikeUserByIds(ids));
    }

    @GetMapping("/getUserCount")
    public Map<String, BigDecimal> getUserCount(@RequestParam String timeRange) {
        return ebikeUserService.getEbikeUserCount(timeRange);
    }
}
